<template>
	<view>
		<!-- 头部内容 -->
		<u-sticky>
			<view class="dingbu mainpadding2">
				<view class="" :style="{paddingTop:menutop+'rpx'}">
					<image src="@/static/image/system/ydddyf.png" style="width: 192rpx;height: 40rpx;" mode=""></image>
				</view>
				<view class="margin_top flexbetween">
					<view class="flexleft" @click="tzxzdz">
						<u-icon name="map-fill" color="#ffa7b4" size="20"></u-icon>
						<view class="tese margin_left1 flexcenter">
							<view class="xiaotese lianghang textcenter margin_right2">{{mdtext}}</view>
							<u-icon name="arrow-down" color="#C01933" size="16"></u-icon>
						</view>
					</view>
					<view class="flexright" @click="tzsous">
						<view class="flexbetween ssbox" style="width: 400rpx;box-sizing: border-box;">
							<view class="flexleft">
								<u-icon name="search" color="#999999" size="20"></u-icon>
								<input type="text" placeholder="请输入搜索内容" class="hei_text main_size bold"
									:disabled="true">
							</view>
							<view class="rightss">搜索</view>
						</view>
					</view>
				</view>
			</view>
		</u-sticky>
		<view class="dingbu mainpadding2" v-if="userInfo">
			<!-- 已充值会员 -->
			<view class="vipcard mainpadding" :style="{backgroundImage:'url('+bagcurl+')'}" v-if="userInfo.is_vip" >
				<view class="flexbetween">
					<view class="flexleft">
						<view class="touxiang margin_right2">
							<image :src="userInfo.avatar_text" mode=""></image>
						</view>
						<view class="">
							<view class="titletext xiaobai">{{userInfo.nickname}}</view>
							<view class="main_size xiaobai margin_top1">{{userInfo.CardNo}}</view>
						</view>
					</view>
					<view class="erwem" @click="jumper('/pages_mine/caigouma')">
						<image src="@/static/image/system/ewmb.png" mode=""></image>
					</view>
				</view>
				<view class=" flexright">
					<view class="dhuaz">
						<!-- VIP -->
						<text class="xiaobai main_size">{{userInfo.vip_text}}</text>
					</view>
				</view>
				<view class="flextop">
					<view class="flexleft">
						<view class="">
							<view class="main_size xiaobai margin_top1">消费总金额：
								<text class="xiaobai main_size">￥{{userInfo.total_zxfprice1 || 0}}</text>
							</view>
							<view class="main_size xiaobai">实付总金额：
								<text class="xiaobai main_size">￥{{userInfo.total_zxfprice || 0}}</text>
							</view>
							<view class="main_size xiaobai margin_top1">共为您节省：
								<text class="xiaobai main_size">￥{{userInfo.total_jsprice || 0}}</text>
							</view>
						</view>
					</view>
					<view class="main_size xiaobai">有效期至：{{userInfo.vip_time}}</view>
				</view>
			</view>
			<!-- 未充值会员 -->
			<image :src="topbanner" v-if="!userInfo.is_vip" mode="widthFix" class="margin_top" @click="tzcwhy" style="width: 100%;"></image>
			<!-- <view class="mainpadding">
				<view class="ershiba xiaobai fonweight textcenter">加入药采购计划，购药专享成本价</view>
				<view class="flexbetween margin_top2">
					<view class="webox beijint1">
						<view class="ershiba xiaofen fonweight">采购主卡</view>
						<view class="smalltext xiaofen nofonweight margin_top1">月卡/季卡/年卡</view>
					</view>
					<view class="">
						<u-icon name="plus" color="#FFFFFF" size="20"></u-icon>
					</view>
					<view class="webox beijint2">
						<view class="ershiba xiaofen fonweight">免费赠送</view>
						<view class="smalltext xiaofen nofonweight margin_top1">亲友卡</view>
					</view>
					<view class="">
						<u-icon name="plus" color="#FFFFFF" size="20"></u-icon>
					</view>
					<view class="webox beijint3">
						<view class="ershiba xiaofen fonweight">新人礼包</view>
						<view class="smalltext xiaofen nofonweight margin_top1">300元折现券</view>
					</view>
				</view>
			</view> -->
		</view>
		<view class="dingbu mainpadding2">
			<image v-if="!is_login" :src="topbanner" mode="widthFix" class="margin_top" @click="tzcwhy" style="width: 100%;"></image>
		</view>
		
		<!-- 轮播图 -->
		<view class="margin_top1">
			<u-swiper :list="list1" circular height="156" radius="0"></u-swiper>
		</view>
		<!--  -->
		<view class="mainpadding">
			<!-- 邀请 -->
			<view class="ybtp1" @click="jumper('/pages_index/fenyongzx')">
				<image :src="yqhyimg" mode=""></image>
			</view>
			<!--商品成本补贴价格表  -->
			<view class="fenbbox flexbetween margin_top2"   @click="switchclass">
				<view class="xiaoka bigtext fonweight" :style="{color:systeminfo.style1}">{{systeminfo.title1}}</view>
				<view class="flexright">
					<view class="xiaoka ershiba nofonweight" :style="{color:systeminfo.style1}">更多</view>
					<u-icon name="arrow-right" :color="systeminfo.style1"></u-icon>
				</view>
			</view>
			<!-- 商品列表 -->
			<view class="flexcenter" v-if="!listone.data.length">
				<view class="placeholderimage" style="margin-top: 50rpx;"></view>
			</view>
			<view class="flexbetween flex_wrap">
				<view class="spbox margin_top dingwei" v-for="item in listone.data" :key="item.Rec" @click="tzspxq(item.Rec)">
					<!-- <view class="jianth"></view> -->
					<view class="shangpt">
						<image :src="item.image_text" mode=""></image>
					</view>
					<view class="huisebox ">
						<view class="sanshier xiaohei fonweight yhxk">{{item.FullName}}</view>
						<view class="flexbetween margin_top1">
							<view class="strongtext xiaohong ">月销量{{item.mouthsales}}</view>
							<view class="strongtext xiaohui ">库存 {{item.stock}}</view>
						</view>
						<view class="strongtext xiaohei yhxk margin_top1" v-if="item.comment_des">最新评价：{{item.comment_des}}</view>
					</view>
					<view class="fensbox ">
						<view class="strongtext xiaoka nofonweight">成本补贴价
							<text class="strongtext xiaoka fonweight">￥{{item.vipprice}}</text>
						</view>
						<!-- <view class="flexbetween margin_top1">
							<view class="smalltext xiaoka nofonweight ">厂商指导价
								<text class="smalltext xiaoka fonweight">￥{{item.RetailStdPrice}}</text>
							</view>
							<view class="smalltext xiaoka nofonweight  textright">可省
								<text class="xiaohong fonweight" style="font-size: 26rpx;">{{item.zjPrice}}</text>
							</view>
						</view> -->
						<view class="">
							<view class=" margin_top1 smalltext xiaoka nofonweight ">厂商指导价
								<text class="smalltext xiaoka fonweight textright">￥{{item.RetailStdPrice}}</text>
							</view>
						</view>
						<view class="flexright margin_top1">
							<view class=" ershil xiaoka nofonweight ">可省</view>
							<text class="xiaohong fonweight" style="font-size: 30rpx;">{{item.zjPrice}}元</text>
						</view>
					</view>
				</view>
			</view>
			<view class="fenbbox flexbetween margin_top2"  @click="switchclass">
				<view class="xiaoka bigtext fonweight" :style="{color:systeminfo.style2}">{{systeminfo.title2}}</view>
				<view class="flexright">
					<view class="xiaoka ershiba nofonweight" :style="{color:systeminfo.style2}">更多</view>
					<u-icon name="arrow-right" :color="systeminfo.style2"></u-icon>
				</view>
			</view>
			<!-- 商品列表 -->
			<view class="flexcenter" v-if="!listtwo.data.length">
				<view class="placeholderimage" style="margin-top: 50rpx;"></view>
			</view>
			<view class="flexbetween flex_wrap">
				<view class="spbox margin_top dingwei" v-for="item in listtwo.data" :key="item.Rec" @click="tzspxq(item.Rec)">
					<!-- <view class="jianth"></view> -->
					<view class="shangpt">
						<image :src="item.image_text" mode=""></image>
					</view>
					<view class="huisebox ">
						<view class="sanshier xiaohei fonweight yhxk">{{item.FullName}}</view>
						<view class="flexbetween margin_top1">
							<view class="strongtext xiaohong ">月销量{{item.mouthsales}}</view>
							<view class="strongtext xiaohui ">库存 {{item.stock}}</view>
						</view>
						<view class="strongtext xiaohei yhxk margin_top1" v-if="item.comment_des">最新评价：{{item.comment_des}}</view>
					</view>
					<view class="fensbox ">
						<view class="strongtext xiaoka nofonweight">成本补贴价
							<text class="strongtext xiaoka fonweight">￥{{item.vipprice}}</text>
						</view>
						<!-- <view class="flexbetween margin_top1">
							<view class="smalltext xiaoka nofonweight ">厂商指导价
								<text class="smalltext xiaoka fonweight">￥{{item.RetailStdPrice}}</text>
							</view>
							<view class="smalltext xiaoka nofonweight  textright">可省
								<text class="smalltext xiaohong fonweight">{{item.zjPrice}}元</text>
							</view>
						</view> -->
						<view class="">
							<view class=" margin_top1 smalltext xiaoka nofonweight ">厂商指导价
								<text class="smalltext xiaoka fonweight textright">￥{{item.RetailStdPrice}}</text>
							</view>
							
						</view>
						<view class="flexright margin_top1">
							<view class=" ershil xiaoka nofonweight ">可省</view>
							<text class="xiaohong fonweight" style="font-size: 30rpx;">{{item.zjPrice}}元</text>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				menutop: 0,
				list1: [],
				bannerList: [],
				topbanner: "",
				userInfo:{},
				page: 1,
				limit: 12,
				listone: {
					data: []
				},
				listtwo: {
					data: []
				},
				systeminfo:{},
				lat:"",
				lng:"",
				mdtext:"",
				referee_id:"",
				bagcurl:"",
				yqhyimg:"",
				is_login: false,
			}
		},
		onShareAppMessage() {
			let _this = this
			return {
				title: "一点点大药房",
				path: "pages/index?code=" + uni.getStorageSync("yqm"),
			}
		},
		onShareTimeline: function() {
			return {
				title: "一点点大药房",
				path: "pages/index?code=" + uni.getStorageSync("yqm"),
			}
		},
		onLoad(options) {
			if(options.code){
				uni.setStorageSync("invite_code",options.code)
			}
			this.getbanner()
			this.system()
			this.initone()
			this.inittwo()
			this.menutop = uni.getMenuButtonBoundingClientRect().top * 2
			this.getlocation()
			// #ifdef MP-WEIXIN
			let _this = this
			const url = decodeURIComponent(options.q) // 获取到二维码原始链接内容
			if (url.indexOf("?") != -1) {
				var str = url.substr(url.indexOf("?") + 1);
				var strs = str.split("&");
				let theRequest = {};
				for (var i = 0; i < strs.length; i++) {
					theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
				}
				_this.referee_id = options.code ? options.code : (theRequest.code ? theRequest.code :
					0);
				if (_this.referee_id != 0) {
					uni.setStorageSync('invite_code', _this.referee_id);
				}
			}
			// #endif
		},
		onShow() {
			this.is_login = httpRequest.checkIsLogin();
			uni.$off("changemdtext")
			uni.$on("changemdtext",data=>{
				console.log(data,"888");
				this.mdtext = data.PosName
			})
			if (httpRequest.checkIsLogin()) {
				this.getuserinfo()
			}else{
				this.userInfo = null
			}
		},
		methods: {
			getlocation() {
				let _this = this
				uni.getLocation({
					type: 'wgs64',
					success: function(res) {
						console.log(res, "获取位置成功");
						_this.lat = res.latitude
						_this.lng = res.longitude
						_this.getmdList()
					},
					fail(err) {
						uni.showModal({
							content: '检测到您没打开定位功能权限，是否去设置打开？',
							confirmText: "确认",
							cancelText: '取消',
							success: (res) => {
								if (res.confirm) {
									uni.openSetting({ //opensetting是调起设置页面的
										success: (res) => {
											console.log(res.authSetting);
											if (res.authSetting ==
												true) { //判断res.authsetting的值是true还是false
												_this.getlocation()
											} else {
												_this.getlocation()
												console.log("拒绝授权");
											}
										}
									})
								} else {
									console.log('取消');
									return false;
								}
							}
						})
						console.log(err, "cuowu");
					}
				});
			},
			getmdList() {
				httpRequest.request('/api/index/shopIndex', 'GET', {
					lat: this.lat,
					lng: this.lng
				}).then(res => {
					// this.mdList = res.data
					this.mdtext = res.data[0].PosName
				})
			},
			initone() { //提现记录
				let _this = this;
				let url = '/api/goodscl/goodsindex'
				let data = {
					index1_show:1
				}
				httpRequest.request(url, 'GET',data, false, false, true).then(res => {
					if (res.code == 1) {
						_this.listone.data = res.data;
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			inittwo() { //提现记录
				let _this = this;
				let url = '/api/goodscl/goodsindex'
				let data = {
					index2_show:1
				}
				httpRequest.request(url, 'GET',data, false, false, true).then(res => {
					if (res.code == 1) {
						_this.listtwo.data = res.data;
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			switchclass(){
				uni.switchTab({
					url:"/pages/class"
				})
			},
			system(){
				httpRequest.request('/api/index/getConfigInfo', 'GET', {}).then(res => {
					this.systeminfo = res.data
				})
			},
			getuserinfo() {
				httpRequest.request('/api/user/index', 'GET', {}).then(res => {
					this.userInfo = res.data
				})
			},
			getbanner() {
				httpRequest.request('/api/index/getAdvertiseList', 'POST', {
					is_more:1,
					advertise_position_id:1
				}).then(res => {
					res.data.forEach(item => {
						this.list1.push(item.image_text)
					})
					this.bannerList = res.data
				})
				httpRequest.request('/api/index/getAdvertiseList', 'POST', {
					is_more: 2,
					advertise_position_id: 2
				}).then(res => {
					this.topbanner = res.data.image_text
				})
				httpRequest.request('/api/index/getAdvertiseList', 'POST', {
					is_more: 2,
					advertise_position_id: 5
				}).then(res => {
					this.bagcurl = res.data.image_text
				})
				httpRequest.request('/api/index/getAdvertiseList', 'POST', {
					is_more: 2,
					advertise_position_id: 6
				}).then(res => {
					this.yqhyimg = res.data.image_text
				})
			},
			// 跳转购买会员
			tzcwhy() {
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/wxlogin"
					})
					return false
				}
				uni.navigateTo({
					url: '/pages_mine/chengweihy'
				})
			},
			jumper(url) {
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/wxlogin"
					})
					return false
				}
				uni.navigateTo({
					url: url
				})
			},
			// 跳转商品详情
			tzspxq(id) {
				uni.navigateTo({
					url: '/pages_index/shangpxq?id='+id
				})
			},
			// 调整选择地址
			tzxzdz() {
				uni.navigateTo({
					url: '/pages_index/xuanzequyu?name='+this.mdtext
				})
			},
			// 跳转搜索
			tzsous() {
				uni.navigateTo({
					url: '/pages_index/sousuo'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.ybtp1 {
		width: 100%;
		height: 143rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.beijint1 {
		background-image: url('@/static/image/system/sy1.png');
	}

	.beijint2 {
		background-image: url('@/static/image/system/sy2.png');
	}

	.beijint3 {
		background-image: url('@/static/image/system/sy3.png');
	}

	.webox {
		// background-color: #ef5212;

		background-size: 100% 100%;
		padding: 10rpx 36rpx 42rpx 10rpx;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
	}

	// 商品列表
	.jianth {
		width: 28rpx;
		height: 38rpx;
		position: absolute;
		right: 42rpx;
		bottom: 48rpx;
		background-size: 100% 100%;
		background-image: url('../static/image/system/jiant.png');
	}

	.fensbox {
		padding: 10rpx 20rpx;
		background: #FED8D2;
		border: 0 0 20rpx 20rpx;
	}

	.huisebox {
		padding: 10rpx 20rpx;
		background: #E6E6E6;
	}

	.spbox {
		width: 48%;
	}

	.shangpt {
		height: 320rpx;
		width: 100%;
		border: 20rpx 20rpx 0 0;

		image {
			width: 100%;
			height: 100%;
			border: 20rpx 20rpx 0 0;
		}
	}

	// 结束
	.fenbbox {
		padding: 20rpx 30rpx;
		background: #FED6D1;
		border: 1rpx solid #E6E6E6;
		border-radius: 25rpx 0rpx 25rpx 0rpx
	}

	.huanbtn {
		font-size: 28rpx;
		font-weight: 400;
		color: #FF6341;
		width: 173rpx;
		height: 50rpx;
		background: linear-gradient(180deg, #FFE6D9 0%, #FFD9A5 100%);
		box-shadow: 0rpx 4rpx 6rpx 1rpx #FB9849;
		border-radius: 30rpx 30rpx 30rpx 30rpx;
	}

	.xhor {
		position: relative;
		z-index: 1;
		width: 123rpx;
		height: 141rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.yqbox {
		padding: 10rpx 107rpx 10rpx 40rpx;
		background: #FD9553;
		border-radius: 60rpx 60rpx 60rpx 60rpx;
	}

	.dhuaz {
		font-size: 107rpx;
		font-weight: 400;
		color: #FFCC00;
	}

	.erwem {
		width: 70rpx;
		height: 70rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.touxiang {
		width: 96rpx;
		height: 96rpx;
		border-radius: 50%;

		image {
			border-radius: 50%;
			width: 100%;
			height: 100%;
		}
	}

	.dingbu {
		background-color: #fed8d3;
	}

	.vipcard {
		// background-image: url("@/static/image/system/vipcard.png");
		width: 100%;
		// height: 345rpx;
		background-size: 100% 100%;
		position: relative;
		box-sizing: border-box;
	}

	.tese {
		max-width: 230rpx;
		min-width: 230rpx;
		background-color: #ffa7b4;
		padding: 10rpx 20rpx;
		border-radius: 50rpx;
		box-sizing: border-box;
	}
</style>